package com.tjetc.service.impl;

import com.tjetc.domain.Scheduling;
import com.tjetc.mapper.CloseApplyMapper;
import com.tjetc.mapper.SchedulingMapper;
import com.tjetc.vo.Result;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.tjetc.mapper.CloseMapper;
import com.tjetc.domain.Close;
import com.tjetc.service.CloseService;

import java.util.List;

@Service
public class CloseServiceImpl implements CloseService{

    @Resource
    private CloseMapper closeMapper;

    @Resource
    private SchedulingMapper schedulingMapper;

    @Resource
    private CloseApplyMapper closeApplyMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return closeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Close record) {
        return closeMapper.insert(record);
    }

    @Override
    public int insertSelective(Close record) {
        return closeMapper.insertSelective(record);
    }

    @Override
    public Close selectByPrimaryKey(Integer id) {
        return closeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Close record) {
        return closeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Close record) {
        return closeMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Close> findAll() {
        return closeMapper.findAll();
    }

    @Override
    public Result getById(Integer id) {
        Close close=closeMapper.getById(id);
        return Result.ok(close);
    }

    @Override
    public Result list() {
        List<Close> list=closeMapper.findAll();
        return Result.ok(list);
    }

    @Override
    public Result addClose(Close close) {
        int rows= closeMapper.addClose(close);
        if (rows > 0) {
            if (close.getIsAgree()==1){
                int row=schedulingMapper.updateStateById(close.getScheduleId());
                return Result.ok(row);
            }
        }
        return Result.ok(rows);
    }

}
